#!/usr/bin/env python
# -*- coding: utf-8 -*-
import vim, string
from vtp import *

Cmd=vim.command
Eval=vim.eval

class VTPManage(object):
    def __init__ (self):
        self.set_engine()

    def set_engine(self):
        init_engine(Eval('g:vtp_engine'))
        self._engine = Eval('g:vtp_engine')

    def translateCursorHover(self):
        word=str(Eval('expand("<cword>")'))
        translate(word)
        msg = translator.result()
        if msg:
            Cmd('call vtp#handleTranslateResult("%s")' % (msg))

    def translate(self, text):
        translate(text, target_lang=str(Eval('g:vtp_target_lang')) )
        return translator.result()

    def translateCursorReplace(self):
        text=vim.eval('expand("<cword>")')
        translate(text)
        res = translator.result()
        print(res)
        if res:
            Cmd('let @t="%s"' % (res['translate_reault']))
            Cmd('normal daw')
            Cmd('normal "tp')

vtpManage = VTPManage()
__all__ = ['vtpManage']
